A simple example
Imagine we measured the relative size of six individual…plants? frogs?
Have measurements at weeks 0, 2, 3, 4, 6, and 8
Some data are missing
Simulating our example
n <- 6
time <- c(0, 2, 4, 6, 8)
betas <- rnorm(n=n, mean = 0.9, sd = 0.25)
sigma <- 0.75
df <- expand.grid(ID = 1:n,
time = time)
df$size <- rnorm(n=nrow(df),
mean=betas[df$ID]*df$time,
sd=sigma)
df$size[df$time == 0] <- 0
df <- df[-sample(1:nrow(df), 10), ]
Simulating our example
Analysis goal
Our research question is whether plants or frogs grow substantially over time.
(And probably we’d have different treatments, but we’re keeping it simple so far.)
How would you analyze these data?
Option 1: ignore the grouping… complete pooling
individuals are essentially identical
m1 <- ulam(
alist(
size ~ dnorm(mu, sigma),
mu <- beta*time,
# priors
beta ~ dnorm(1,1),
sigma ~ dexp(2)
), data = df
)
mean sd 5.5% 94.5% n_eff Rhat4
beta 0.7817148 0.05464689 0.7027511 0.8676466 304.5726 0.998089
sigma 1.1559751 0.18563845 0.8952203 1.4708731 332.8428 1.003157
Option 1: ignore the grouping… complete pooling
Option 2: every individual (or group) is different… no pooling
m2 <- ulam(
alist(
size ~ dnorm(mu, sigma),
mu <- beta[ID]*time,
# priors
beta[ID] ~ dnorm(1, 1),
sigma ~ dexp(2)
), data = df
)
mean sd 5.5% 94.5% n_eff Rhat4
beta[1] 0.6255864 0.07320952 0.5112366 0.7375515 612.3183 1.0011711
beta[2] 1.0211894 0.06275966 0.9159211 1.1224503 505.3025 0.9985341
beta[3] 0.5695921 0.28890830 0.1000682 1.0489905 879.6874 1.0001581
beta[4] 0.9185527 0.05630575 0.8372090 1.0010603 561.9530 0.9982647
beta[5] 0.4354022 0.06661095 0.3252638 0.5414363 618.9719 1.0013894
beta[6] 0.8040047 0.09282635 0.6572829 0.9610849 441.2600 0.9979987
sigma 0.6329067 0.12479079 0.4662342 0.8700223 380.4414 0.9982784
Option 2: every individual (or group) is different… no pooling
Option 2: every individual (or group) is different… no pooling
Option 2b: average across group estimates
![]()
mean across individuals estimates
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.5712 0.6916 0.7288 0.7291 0.7593 0.8912
standard deviation among individual estimates
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.1551 0.2192 0.2453 0.2552 0.2811 0.4988
Option 3: partial pooling
every individual (or group) is different, but not that different
m3 <- ulam(
alist(
size ~ dnorm(mu, sigma),
mu <- beta[ID]*time,
# priors
beta[ID] ~ dnorm(beta_mu, beta_sd),
beta_mu ~ dnorm(1,1),
beta_sd ~ dexp(1),
sigma ~ dexp(2)
), data = df
)
mean sd 5.5% 94.5% n_eff Rhat4
beta_mu 0.7350791 0.1424153 0.4985496 0.9628633 342.0578 0.9997341
beta_sd 0.2984620 0.1399021 0.1432614 0.5721289 364.6213 1.0083107
sigma 0.6394945 0.1406827 0.4642217 0.8840324 399.8765 1.0020758
Option 3: partial pooling
Option 3: partial pooling
slightly changed predictions
![]()
Predictions are drawn towards the mean, all else equal.